package com.gzyj.jtt808.v2013.protocol;

import com.gzyj.jtt808.utils.HexBytesUtil;
import com.gzyj.jtt808.v2013.Package;
import com.gzyj.jtt808.v2013.enums.BusinessDataType;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.Serializable;

@Data
public class JTT808_0x8106 extends Package implements Serializable {
    private Integer ParameterCount;
    private Integer[] Parameters;

    public JTT808_0x8106() {
        super(BusinessDataType.查询指定终端参数.getCode());
    }


    @Override
    public void encodeImpl(ByteBuf buf) {
        buf.writeByte(this.ParameterCount);
        for (int t = 0; t < this.ParameterCount; t++) {
            buf.writeInt(this.Parameters[t]);
        }
    }

    @Override
    public JTT808_0x8106 decodeImpl(ByteBuf buf) {
        byte[] temp = HexBytesUtil.readByOffset(buf, 1);
        this.ParameterCount = Integer.parseInt(HexBytesUtil.bytesToHex(temp), 16);
        this.Parameters = new Integer[this.ParameterCount];
        for (int i = 0; i < this.ParameterCount; i++) {
            this.Parameters[i] = HexBytesUtil.byteArrayToInt(HexBytesUtil.readByOffset(buf, 4));
        }

        return this;
    }
}
